/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Entidades.Organo;
import Entidades.SolicitudTraslado;
import Servicios.Dao.Impl.OrganoDaoImpl;
import Servicios.Dao.Impl.SolicitudTrasladoDaoImpl;
import Servicios.Dao.OrganoDao;
import Servicios.Dao.SolicitudTrasladoDao;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author TRACY
 */
public class GestionarCotizacion1 extends javax.swing.JFrame {
    GestionarCotizacion2 gestionarCotizacion2;
    public Connection cn;
    SolicitudTrasladoDao solicitudTrasladoDao;
    OrganoDao organoDao;
    SolicitudTraslado solicitudtraslado;

    /**
     * Creates new form GestionarCotizacion1
     */
    public GestionarCotizacion1(Connection cn){
        this.cn =cn;
        solicitudTrasladoDao = new SolicitudTrasladoDaoImpl(cn);
        organoDao = new OrganoDaoImpl(cn);
        initComponents();
        LlenarListaSolicitudTraslados();
        
    }

       
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        tbsol = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        tbsol.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Código", "Fecha", "Origen"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tbsol.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbsolMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tbsol);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/eliminar-boton-cuadrado-rojo-aspa.png"))); // NOI18N
        jButton1.setText("Cancelar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/aceptamos-icono-4963-48.png"))); // NOI18N
        jButton2.setText("Aceptar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("                SOLICITUDES  DE FONDOS");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(96, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(21, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(106, 106, 106)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(146, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(111, 111, 111))))
            .addGroup(layout.createSequentialGroup()
                .addGap(180, 180, 180)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 353, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 243, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(43, 43, 43))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void tbsolMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbsolMouseClicked
      solicitudtraslado = new SolicitudTraslado();
        if (evt.getClickCount() == 2) { 
            int fila = tbsol.rowAtPoint(evt.getPoint());
            int columna = tbsol.columnAtPoint(evt.getPoint());
            if ((fila > -1) && (columna > -1)){
                solicitudtraslado = solicitudTrasladoDao.buscarSolicitud(String.valueOf(tbsol.getValueAt(fila, 0)));
                try {
                    GestionarCotizacion2 gestionarCotizacion2 = new GestionarCotizacion2(solicitudtraslado.getIDSolicitud(),cn);
                    //gestionarCotizacion2 = new GestionarCotizacion2();
                    gestionarCotizacion2.setVisible(true);
                } catch (Exception ex) {
                    System.out.println("Error: "+ex);
                }
            }
        } 
       
    }//GEN-LAST:event_tbsolMouseClicked
 
    
    public Connection getCn() {
        return cn;
    }
    
     
     public void LlenarListaSolicitudTraslados (){
         List<SolicitudTraslado> sts = solicitudTrasladoDao.buscarSolicitudTraslado();
         Organo organo;
         Object[] fila=new Object[4];
         int j=0;
         for (int i = 0; i < sts.size(); i++) {
            fila[j]=sts.get(i).getIDSolicitud();
            j++;
            fila[j]=sts.get(i).getFechaEmision();
            j++;
            organo = organoDao.buscarOrganoxID(sts.get(i).getIDOrgano());
            fila[j]= organo.getNombreOrgano();
            ((DefaultTableModel) tbsol.getModel()).addRow(fila);
            j=0;
         }
    }
     

    /**
     * @param args the command line arguments
     */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable tbsol;
    // End of variables declaration//GEN-END:variables
}
